<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/20
 * Time: 9:20
 */
namespace app\index\controller;

use think\Controller;

class Task extends Base
{


    private $task_key_model = null;

    private $task_model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->task_key_model = new \app\common\model\shop\task\Key;
        $this->task_model   = new \app\common\model\shop\Task;
    }



    //点击任务跳转到
    public function task_act($task=NULL){

//        if($this->userInfo["status"]==0){
//            renderJson("您已被禁用，可联系平台管理员解禁",0);
//        }

        $task_info = $this->task_key_model
                    ->with(["task"=>function($q){$q->with(["shop"=>function($qr){$qr->field("shop_name,shop_id");}])->where("task_status",2);}])
                    ->where("take_key_id",$task)
                    ->find();
        $rankTypeList = $this->task_model->getRankingType();

        $browseTime = $this->task_model->getBrowseTime();

        if($task_info->task->shop->shop_name){
            $shop_name = $task_info->task->shop->shop_name;
            //$task_info->task->shop->shop_name = iconv('GB2312', 'UTF-8',  substr($shop_name,0,1))."**".substr($shop_name,3);
            $task_info->task->shop->shop_name =  $this->substr_cut($shop_name,1,2);
        }
        $this->assign("op",input("op"));//是否显示
        $this->assign("task_info",$task_info);
        $this->assign("rankTypeList",$rankTypeList);
        $this->assign("browseTime",$browseTime);
        return $this->fetch('shop/orderDetail');

    }

    public function substr_cut($user_name,$start,$end){

        $strlen     = mb_strlen($user_name, 'utf-8');

        $firstStr     = mb_substr($user_name, 0, $start, 'utf-8');

        $lastStr     = mb_substr($user_name, $end+1,$strlen, 'utf-8');

        $len = $end-$start+1;

        return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $len). $lastStr;

    }


}